home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Programming / Python-1.4 / Source / Amiga / Python_netlib / linkntoa.c < prev    next >
C/C++ Source or Header  |  1994-09-29  |  1KB  |  51 lines

  1. RCS_ID_C = "$Id: linkntoa.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      linkntoa.c - link level address printing
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  *
  9.  *      Copyright © 1991 Regents of the University of California.
  10.  */
  11.  
  12. #include <sys/types.h>
  13. #include <sys/socket.h>
  14. #include <net/if.h>
  15. #include <net/if_dl.h>
  16. #include <string.h>
  17.  
  18. static char hexlist[] = "0123456789abcdef";
  19.  
  20. char *
  21. link_ntoa(sdl)
  22.     register const struct sockaddr_dl *sdl;
  23. {
  24.     static char obuf[64];
  25.     register char *out = obuf; 
  26.     register int i;
  27.     register u_char *in = (u_char *)LLADDR(sdl);
  28.     u_char *inlim = in + sdl->sdl_alen;
  29.     int firsttime = 1;
  30.  
  31.     if (sdl->sdl_nlen) {
  32.         bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen);
  33.         out += sdl->sdl_nlen;
  34.         *out++ = ':';
  35.     }
  36.     while (in < inlim) {
  37.         if (firsttime) firsttime = 0; else *out++ = '.';
  38.         i = *in++;
  39.         if (i > 0xf) {
  40.             out[1] = hexlist[i & 0xf];
  41.             i >>= 4;
  42.             out[0] = hexlist[i];
  43.             out += 2;
  44.         } else
  45.             *out++ = hexlist[i];
  46.     }
  47.     *out = 0;
  48.     return(obuf);
  49. }
  50.  
  51.